import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { Router } from '@angular/router';
import { makeupDescentArrs } from '../recyc-market-manage.pipe';
import { LovemakeupDescentService } from '../services/love-makeup-descent.service';

@Component({
  selector: 'app-love-makeup-record',
  templateUrl: './love-makeup-record.component.html',
  styleUrls: ['./love-makeup-record.component.scss']
})
export class LoveMakeupRecordComponent implements OnInit {
  
  searchOptions = [
    { type: 1, labelText: '用户ID', valueKey: 'userId', value: '' },
    { type: 1, labelText: '加价促销', valueKey: 'activity', value: '', placeholder: '请输入促销ID/名称' },
    { type: 1, labelText: '订单编号', valueKey: 'okey', value: '' },
    { type: 3, labelText: '下单时间', valueKey: ['beginTime', 'endTime'], value: [], isTimeSelect: true }
  ];
  searchParams: any = {};

  tableParams: any = {
    loading: false,
    tableData: [],
    page: 1,
    pageSize: 20,
    total: 0
  }

  constructor(
    private router: Router,
    private message: NzMessageService,
    private services: LovemakeupDescentService
  ) { }

  ngOnInit(): void {
  }

  async loadTable() {
    let params = {
      ...this.searchParams,
      page: this.tableParams.page,
      pageSize: this.tableParams.pageSize
    }
    this.tableParams.loading = true;
    const res: any = await this.services.getDescentRecordList(params);
    this.tableParams.loading = false;

    if (res.code === 0) {
      const { records, total } = res.data || {};
      this.tableParams.tableData = records || [];
      this.tableParams.total = total || 0;
    } else {
      this.message.error(res.message);
    }
  }

  queryData(params: any) {
    this.searchParams = params;
    this.tableParams.page = 1;
    this.loadTable();
  }

  resetData(params: any) {
    this.searchParams = params;
    this.tableParams.page = 1;
    this.loadTable();
  }

  // PageIndex Change
  onPageIndexChange(index: number) {
    this.tableParams.page = index;
    this.loadTable();
  }
  
  // PageSize Change
  onPageSizeChange(sizeNum: number) {
    this.tableParams.page = 1;
    this.tableParams.pageSize = sizeNum;
    this.loadTable();
  }
}
